package com.gitee.sop.layui.adminserver.module.background.develop.manager;

import com.gitee.sop.layui.adminserver.module.background.develop.mapper.SysFunctionRoleRelationMapper;
import com.gitee.sop.layui.adminserver.plugins.cache.util.CacheUtil;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: huwei
 * @date: 2019/12/3 9:26
 * @version: 1.0.0
 */
@Component
public class SysFunctionRoleRelationCacheManager {
    @Lazy
    @Resource
    private SysFunctionRoleRelationMapper sysFunctionRoleRelationMapper;


    public List<String> listFunctionNameByFunctionId(int functionId) {
        return CacheUtil.getOrPutIfAbsent(functionId + "", () -> sysFunctionRoleRelationMapper.selectFunctionNameByFunctionId(functionId), this.getClass().getName());
    }

    public void removeByRoleIdAndCreatedUuid(int functionRoleId) {
        CacheUtil.clearDomain(this.getClass().getName());
        sysFunctionRoleRelationMapper.deleteByRoleId(functionRoleId);
    }
}
